package com.hl.sfzy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.ConsultantCertificates;
import com.hl.sfzy.service.ConsultantCertificatesService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/certificates")
public class ConsultantCertificatesController {
    @Autowired
    private ConsultantCertificatesService consultantCertificatesService;
    @RequestMapping("/selectAll")
    public R selectAll(@RequestParam(required = false ,defaultValue = "1")int pageNum,
                       @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<ConsultantCertificates> info = new PageInfo<>(consultantCertificatesService.selectAll());
        return R.ok(info);
    }
    @RequestMapping("/selectById")
    public R selectById(Long id){
        return R.ok(consultantCertificatesService.selectById(id));
    }
    @RequestMapping("/delete")
    public R delete(Long id){
        int count = consultantCertificatesService.deleteByPrimaryKey(id);
        if (count == 1) {
            return R.ok("删除成功");
        }else {
            return R.ok("删除失败");
        }
    }
    @RequestMapping("/insert")
    public R insert(ConsultantCertificates consultantCertificates){
        return R.ok(consultantCertificatesService.insert(consultantCertificates));
    }
    @RequestMapping("/insertSelective")
    public R insertSelective(ConsultantCertificates consultantCertificates){
        return R.ok(consultantCertificatesService.insertSelective(consultantCertificates));
    }
    @RequestMapping("/updateById")
    public R updateById(ConsultantCertificates consultantCertificates){
        return R.ok(consultantCertificatesService.updateByPrimaryKeySelective(consultantCertificates));
    }
    @GetMapping("/findByConsultantId")
    public R findByConsultantId(Long consultantId){
        return R.ok(consultantCertificatesService.findByConsultantId(consultantId));
    }
}
